package com.example.netty.channel.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyHanlder extends ChannelInboundHandlerAdapter {
    private static final Logger logger= LoggerFactory.getLogger(MyHanlder.class);

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        logger.info(msg.toString());
        ctx.channel().writeAndFlush(msg);
        super.channelRead(ctx, msg);

    }

    @Override
    public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
        NioSocketChannel nioSocketChannel= (NioSocketChannel)ctx.channel();
        logger.info(
            nioSocketChannel.remoteAddress().getHostString() + ":" + nioSocketChannel.remoteAddress()
                .getPort()+"下线了");
        super.channelUnregistered(ctx);
    }
}
